<template>
    <div class="register-page">
      <div class="register-container">
        <h2>注册</h2>
  
        <!-- 注册表单 -->
        <form @submit.prevent="handleSubmit">
          <div>
            <label for="username">用户名:</label>
            <input id="username" v-model="registerData.username" type="text" required />
          </div>
          <div>
            <label for="password">密码:</label>
            <input id="password" v-model="registerData.password" type="password" required />
          </div>
          <div>
            <label for="confirmPassword">确认密码:</label>
            <input id="confirmPassword" v-model="confirmPassword" type="password" required />
          </div>
          <div>
            <label for="email">邮箱:</label>
            <input id="email" v-model="registerData.email" type="email" style="width: 60%;margin-right: 10%;" required />
            <button @click="sendVerificationCode" type="button">发送验证码</button>
          </div>
          <div>
            <label for="verificationCode">验证码:</label>
            <input id="verificationCode" v-model="verificationCode" type="text" required />
          </div>
          <div>
            <button type="submit">注册</button>
          </div>
        </form>
        
        <div>
          <router-link to="/login">已有账号？去登录</router-link>
        </div>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
      confirmPassword: '',
      verificationCode: '',
        registerData: {
          username: '',
          password: '',
          email: '',
          birthday: '',
          gender: ''
        }
      };
    },
    methods: {
      sendVerificationCode() {
        console.log('发送验证码到邮箱:', this.registerData.email);
        // 这里可以添加发送验证码的逻辑，比如调用API发送验证码
      },
      handleSubmit() {
        if (this.registerData.password !== this.confirmPassword) {
          alert('两次输入的密码不一致');
          return;
        }
        console.log('尝试注册用户:', this.registerData);
        this.request.post("/admins/register", this.registerData).then(res => {
          console.log(res);
          
        })
        // 这里可以添加实际的注册逻辑，比如调用API进行注册
      }
    }
  };
  </script>
  
  <style scoped>
  .register-page {
    background-image: url('~@/assets/images/login.jpg'); /* 使用 Webpack 解析路径 */
    background-size: cover; /* 覆盖整个区域 */
    background-position: center; /* 图片居中 */
    background-repeat: no-repeat; /* 防止图片重复 */
    height: 100vh;
  }
  
  .register-container {
    max-width: 400px;
    margin-left: 60%;
    padding: 20px;
    border: 1px solid #ccc;
    border-radius: 5px;
  }
  
  h2 {
    text-align: center;
  }
  
  form div {
    margin-bottom: 15px;
  }
  
  label {
    display: block;
    margin-bottom: 5px;
  }
  
  input, select {
    width: calc(100% - 22px);
    padding: 10px;
    margin-bottom: 10px;
  }
  
  button[type="button"] {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    padding: 5px 10px;
    cursor: pointer;
  }
  
  button[type="submit"] {
    width: 100%;
    padding: 10px;
    background-color: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
  }
  
  button[type="submit"]:hover {
    background-color: #45a049;
  }
  </style>